package com.ronri.ams.task;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cz.nongyetongv5.R;
import com.ronri.viewpagerindicator.TitlePageIndicator;
import com.zhy.autolayout.AutoLayoutActivity;

/**
 * 文件：ams.java
 * 包名：com.ronri.ams.task;   --- 正式发布时需要修正
 * 说明：轮播组件
 * 作者：MS During
 * 日期：2017/5/6
 * 历史：
 */
public class activity_detect_summray extends AutoLayoutActivity {

    private TitlePageIndicator tpiIndicator;
    // 分页视图标题
    private  String[] szTabTitle = {"例行监测","监督抽检","三品认证","风险评估(专项)","农业环境(普查)","其他(委托)"};

    // 列表控件
    private Context mContext = null;

    /**
     * 适配器代码
     */
    class TabAdapter extends FragmentPagerAdapter {

        public TabAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {

            fragment_projectlist fragment = fragment_projectlist.newInstance();

            Bundle args = new Bundle();
            args.putInt("type", 2);
            args.putString("args",szTabTitle[position]);
            args.putInt("single",position+1);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public int getCount() {
            return szTabTitle.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return szTabTitle[position];
        }
    }

    /***
     * 初始化视图
     */
    private void initView() {
        TabAdapter adapter = new TabAdapter(getSupportFragmentManager());

        ViewPager viewPager = (ViewPager)findViewById(R.id.vpNewListView);
        viewPager.setAdapter(adapter);

        tpiIndicator = (TitlePageIndicator) findViewById(R.id.tpiIndicator);
        tpiIndicator.setViewPager(viewPager);

        RelativeLayout btView = (RelativeLayout)findViewById(R.id.btnBack);

        btView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

//        /*tpiIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageSelected(int postion) {
//                TabAdapter fragment =  (TabAdapter) getSupportFragmentManager()
//                        .getFragments().get(postion);
//
//                fragment.refreshListView(false);
//
//                if (fragment.getUnreadlist()) {
//                    titleState.setText("");
//                } else {
//                    titleState.setText("");
//
//                }
//            }
//
//            @Override
//            public void onPageScrolled(int arg0, float arg1, int arg2) {
//
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int arg0) {
//
//            }
//        });*/
//
//        //这里是为了清楚TabPageIndicator时报的ViewPager has not been bound异常，先给TabPageIndicator设置android:visibility="gone"
//        /// indicator.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_projectlist);
        mContext = this;

        Log.i("aaa","activity_detect_summray");
        TextView title = (TextView)findViewById(R.id.title_text_tv);
        title.setText("抽检结果");
        initView();
    }
}
